package com.ssy.lingxi.platform.manage.controller.content;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.entity.content.ContentAdvert;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonStatusRequest;
import com.ssy.lingxi.platform.manage.model.request.content.ContentAdvertPageRequest;
import com.ssy.lingxi.platform.manage.model.request.content.ContentAdvertRequest;
import com.ssy.lingxi.platform.manage.service.content.IContentAdvertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @menu 内容管理 - 广告管理
 * @author fhj
 * @version 2.0.0
 * @date 2020/9/17
 */
@Api(tags = "内容管理 - 广告管理")
@RestController
@RequestMapping("/manage/contentAdvert")
public class ContentAdvertController extends BaseController {

    @Resource
    private IContentAdvertService contentAdvertService;

    @ApiOperation(value = "列表")
    @GetMapping("/page")
    public Wrapper<PageData<ContentAdvert>> page(ContentAdvertPageRequest request) {
        return contentAdvertService.page(request);
    }

    @ApiOperation(value = "详情")
    @GetMapping(value = "/get")
    public Wrapper<ContentAdvert> get(@Validated CommonIdRequest request) {
        return contentAdvertService.get(request);
    }

    @ApiOperation(value = "新增")
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Validated({ContentAdvertRequest.Add.class}) ContentAdvertRequest request) {
        return contentAdvertService.add(request, getSysUser());
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Validated({ContentAdvertRequest.Update.class}) ContentAdvertRequest request) {
        return contentAdvertService.update(request, getSysUser());
    }

    @ApiOperation(value = "上架/下架")
    @PostMapping(value = "/updateStatus")
    public Wrapper<Void> updateStatus(@RequestBody @Validated ({CommonStatusRequest.Shelf.class}) CommonStatusRequest request) {
        return contentAdvertService.updateStatus(request, getSysUser());
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Validated CommonIdRequest request) {
        return contentAdvertService.delete(request, getSysUser());
    }

    @ApiOperation(value = "根据栏目获取所有")
    @GetMapping("/findAllByColumnType")
    public Wrapper<List<ContentAdvert>> findAllByColumnType(Integer columnType) {
        return contentAdvertService.findAllByColumnType(columnType);
    }
}
